package com.liming.admin.controller;

import com.liming.common.pojo.dto.PageDTO;
import com.liming.common.pojo.dto.product.AddBrandDTO;
import com.liming.common.pojo.dto.product.UpdateBrandDTO;
import com.liming.common.pojo.vo.PageVO;
import com.liming.common.pojo.vo.product.BrandVO;
import com.liming.common.result.LMResult;
import com.liming.product.client.BrandClient;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 品牌
 *
 * @author liming
 * @date 2025/1/15
 */
@Slf4j
@RestController
@AllArgsConstructor
@Tag(name = "品牌接口-Web")
@RequestMapping("/admin/brand")
public class BrandController {

    private final BrandClient brandClient;

    @Operation(
            summary = "列表",
            responses = {
                    @ApiResponse(responseCode = "1", description = "获取成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = BrandVO.class))
                    })
            }
    )
    @GetMapping
    public LMResult<PageVO<BrandVO>> page(PageDTO pageDTO, @RequestParam(required = false) String name) {
        return LMResult.success(brandClient.page(pageDTO, name));
    }

    @Operation(
            summary = "详情",
            responses = {
                    @ApiResponse(responseCode = "1", description = "获取成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = BrandVO.class))
                    })
            }
    )
    @GetMapping("{id}")
    public LMResult<BrandVO> get(@PathVariable Long id) {
        return LMResult.success(brandClient.get(id));
    }

    @Operation(summary = "新增")
    @PostMapping
    public LMResult<Boolean> add(@RequestBody AddBrandDTO addBrandDTO) {
        return LMResult.success(brandClient.add(addBrandDTO));
    }

    @Operation(summary = "更新")
    @PutMapping
    public LMResult<Boolean> update(@RequestBody UpdateBrandDTO updateBrandDTO) {
        return LMResult.success(brandClient.update(updateBrandDTO));
    }

    @Operation(summary = "更新 - 精选")
    @PutMapping("selected/{id}")
    public LMResult<Boolean> updateSelected(@PathVariable Long id) {
        return LMResult.success(brandClient.updateSelectedById(id));
    }

    @Operation(summary = "删除")
    @DeleteMapping("{id}")
    public LMResult<Boolean> delete(@PathVariable Long id) {
        return LMResult.success(brandClient.delete(id));
    }


}



